
namespace AutomaticLogin
{
    using System;
    using System.Xml.Serialization;
    using System.Xml;
    using System.Collections.Generic;
    using System.Text;

    public class LoginInfos
    {
        private Dictionary<string, LoginInfo> m_List = new Dictionary<string, LoginInfo>();
        
        public LoginInfos() { }

        
        public LoginInfos(string xml)
        {
            XmlDocument dom = new XmlDocument();
            dom.LoadXml(xml);
            Build(dom.ChildNodes[0]);
        }

        private void Build(XmlNode node)
        {
            foreach (XmlNode child in node)
            {
                LoginInfo li = new LoginInfo(child);
                m_List[li.key] = li;
            }
        }

        public LoginInfo this[string key]
        {
            get
            {
                if(!m_List.ContainsKey(key)) return null;
                return m_List[key];
            }
            set
            {
                m_List[key] = value;
            }
        }

        public string ToXml()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(@"<LoginInfos>");
            foreach (LoginInfo li in m_List.Values)
            {
                sb.AppendLine(li.ToXml());
            }
            sb.AppendLine(@"</LoginInfos>");
            return sb.ToString();
        }

    }
}
